define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pigai/shenhe/index' + location.search,
                    add_url: 'pigai/shenhe/add',
                    // edit_url: 'pigai/shenhe/edit',
                    // del_url: 'pigai/shenhe/del',
                    multi_url: 'pigai/shenhe/multi',
                    import_url: 'pigai/shenhe/import',
                    table: 'list_one',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id'), operate: false},
                        {
                            field: 'pigai_numz',
                            title: __('批单暂存号'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: function (value, row, index) {
                                if (value) {
                                    if(row.batch_state == 1){
                                        return '<p style="color:#4c4c4c;font-weight: 700;border: 1px solid #4c4c4c;border-radius: 4px;width: 22px;height: 22px;line-height: 20px;text-align: center;display: inline-block;margin: 0;">退</p> ' +value;
                                    }
                                    if(row.batch_state == 2){
                                        return '<p style="color:#0090ff;font-weight: 700;border: 1px solid #0090ff;border-radius: 4px;width: 22px;height: 22px;line-height: 20px;text-align: center;display: inline-block;margin: 0;">改</p> ' +value;
                                    }
                                    if(row.batch_state == 3){
                                        return '<p style="color:#F00;font-weight: 700;border: 1px solid #F00;border-radius: 4px;width: 22px;height: 22px;line-height: 20px;text-align: center;display: inline-block;margin: 0;">增</p> ' +value;
                                    }
                                    return value;
                                } else {
                                    return '-';
                                }
                            }
                        },
                        {
                            field: 'tong_number',
                            title: __('服务单号'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: function (value, row, index) {
                                if (value) {
                                    return value;
                                } else {
                                    return '-';
                                }
                            }
                        },
                        {
                            field: 'main_free',
                            title: __('服务费'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'car_num',
                            title: __('车牌号'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'car_vin',
                            title: __('车架号'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        // {field: 'ginseng_name', title: __('参统人'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {
                            field: 'learned_name',
                            title: __('被服务人'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'yw_hetong_time',
                            title: __('核统日期'),
                            operate: false,
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'plan_strattime',
                            title: __('服务起期'),
                            operate: false,
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        // {
                        //     field: 'yw_hetongpeo',
                        //     title: __('审核人'),
                        //     operate: false,
                        //     table: table,
                        //     class: 'autocontent',
                        //     formatter: function (value, row, index) {
                        //         if (value) {
                        //             return value;
                        //         } else {
                        //             return '-';
                        //         }
                        //     }
                        // },
                        {
                            field: 'status',
                            title: __('状态'),
                            searchList: {
                                "2": __(' 二级审核(批单) '),
                            },
                            custom: {
                                0: 'success',
                                1: 'danger',
                                2: 'warning',
                                3: 'info',
                                4: 'default',
                                5: 'primary',
                                6: 'huang',
                                7: 'zi'
                            },
                            formatter: Table.api.formatter.label,
                            operate: false
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'details',
                                    text: __('去审核'), // 按钮文字，语言在对应的lang文件设置
                                    title: __('二级审核(批单)'), // 提示
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: '', // 更换图标
                                    url: 'pigai/shenhe/details',
                                    extend: 'data-area=["100%","100%"]',
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        details: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },

        }
    };
    return Controller;
});
